//
//  PickNumShuangSeQiuListViewController.m
//  PlayBall
//
//  Created by Edward Zhang on 12-5-10.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "JddPickNumShuangSeQiuListViewController.h"
#import "JddShuangSeQiuListItemCell.h"
#import "JddShuangSeQiuNumber.h"
#import "JddPickNumShuangSeQiuViewController.h"
#import "JddViewControllerManager.h"


@interface JddPickNumShuangSeQiuListViewController ()

@end

@implementation JddPickNumShuangSeQiuListViewController

@synthesize numberListTable;
@synthesize multipleTextField;
@synthesize noteAmountLabel;
@synthesize multipleLabel;
@synthesize bgScrollView;
@synthesize buybutton;
@synthesize moneyAmountLabel;


SHARED_VIEW_CONTROLLER_IMPLEMENT(JddPickNumShuangSeQiuListViewController);

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    
    NSCharacterSet *cs;
    cs = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789\n"]invertedSet];
    
    NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs]componentsJoinedByString:@""]; //按cs分离出数组,数组按@""分离出字符串
    
    BOOL canChange = [string isEqualToString:filtered];
    
    if (!canChange) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
                                                        message:@"倍数只能输入数字"
                                                       delegate:nil
                                              cancelButtonTitle:@"确定"
                                              otherButtonTitles:nil,nil ];
        [alert show];
        return NO;
    }

    if ([string length] + range.location > 3) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
                                                        message:@"倍数不能大于999"
                                                       delegate:nil
                                              cancelButtonTitle:@"确定"
                                              otherButtonTitles:nil,nil ];
        [alert show];
        return NO;
    }
    
    if ([textField.text length]== 0) {
        if ([string isEqualToString:@"0"]) {
            return NO;
        }else {
            moneyAmountLabel.text = [NSString stringWithFormat:@"%d彩豆", noteAmount * [[textField.text stringByReplacingCharactersInRange:range withString:string] intValue] * 2];
            return YES;
        }   
    }

    if (range.location>=3) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
                                                        message:@"倍数不能大于999"
                                                       delegate:nil 
                                              cancelButtonTitle:@"确定" 
                                              otherButtonTitles:nil,nil ];
        [alert show];
        return NO;
    }else {
        moneyAmountLabel.text = [NSString stringWithFormat:@"%d彩豆", noteAmount * [[textField.text stringByReplacingCharactersInRange:range withString:string] intValue] * 2];
        return YES;
    }
    
}



- (BOOL)textFieldShouldClear:(UITextField *)textField{
    return  YES;
}// clear button事件,返回NO过滤之
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    return YES;
}// 'return' key事件.返回NO过滤之


- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTapGesture:)];
    tapGestureRecognizer.delegate = self;
    [self.bgScrollView addGestureRecognizer:tapGestureRecognizer];
    
    [self.bgScrollView setContentOffset:CGPointMake(0, 213/*buybutton.frame.size.height + buybutton.frame.origin.y - multipleTextField.frame.origin.y + multipleTextField.frame.size.height*/)animated:YES];
    return YES;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
    if ([touch.view isDescendantOfView:buybutton]) {
        return NO;
    }
    return YES;
}

-(void)destoryView{
    numberArray = [[NSMutableArray alloc] init];    
    [numberListTable reloadData];
     multipleTextField.text = @"1";
    [multipleTextField resignFirstResponder];
    noteAmount = 0;
    for (JddShuangSeQiuNumber *ssqNumber in numberArray) {
        if ([ssqNumber.redBallArray count] != 6 ||
            [ssqNumber.blueBallArray count] != 1) {
            noteAmount += [JddCommonFunction countShuangSeQiuTotalNumber:[ssqNumber.redBallArray count] blueBallAmount:[ssqNumber.blueBallArray count]];
        }
        else {
            noteAmount++;
        }
    }
    noteAmountLabel.text = [NSString stringWithFormat:@"%d注", noteAmount];
    multipleLabel.text = [NSString stringWithFormat:@"%@倍", multipleTextField.text];
    moneyAmountLabel.text = [NSString stringWithFormat:@"%d彩豆", noteAmount * [multipleTextField.text intValue] * 2];
    
    discountNo = [NSMutableString string];
    discountAmount = 0;
}


//[JddCommonFunction setWaitingViewHidden:NO fromController:self];
//JddBuyLotteryOperation *operation2 = [[JddBuyLotteryOperation alloc] init];
//operation2.delegate = self;
//JddLotteryIssue *ls = ((JddPickNumShuangSeQiuViewController *)self.fromController).currentLotteryIssue;
//
//operation2.lotteryTypeId = [NSNumber numberWithInt:5];
//operation2.issueId = [NSNumber numberWithInt:[ls.code intValue]];
//operation2.multiple = [NSNumber numberWithInt:[multipleTextField.text intValue]];
//operation2.moneyAmount = [NSNumber numberWithFloat:noteAmount * [multipleTextField.text intValue] * 2];
//operation2.lotteryNumber = [self lotteryNumberList];

- (IBAction)coBuyBtnClick:(id)sender {
    if([self checkValue]){
    JddLotteryIssue *ls = ((JddPickNumShuangSeQiuViewController *)self.fromController).currentLotteryIssue;
    [FaQiHeMaiViewController sharedInstance].bs = [multipleTextField.text intValue];
    [FaQiHeMaiViewController sharedInstance].lotID = LOTTERY_TYPE_ID_SHUANGSEQIU;
    [FaQiHeMaiViewController sharedInstance].issueID = ls.code;
    [FaQiHeMaiViewController sharedInstance].issueName = ls.name;
    [FaQiHeMaiViewController sharedInstance].issueNameTitle = [NSString stringWithFormat:@"双色球第%@期合买",ls.name];
    [FaQiHeMaiViewController sharedInstance].allMoney = noteAmount * [multipleTextField.text intValue] * 2;
    [FaQiHeMaiViewController sharedInstance].lotteryNumber = [self lotteryNumberList];
    [[JddViewControllerManager sharedInstance].navigationController pushViewController:[FaQiHeMaiViewController sharedInstance] animated:YES];
    }
}

- (IBAction)handleSingleTapGesture:(UITapGestureRecognizer*)sender{
    [multipleTextField resignFirstResponder];
    if ([multipleTextField.text length]==0) {
        multipleTextField.text = @"1";
    }
    multipleLabel.text = [NSString stringWithFormat:@"%@倍", multipleTextField.text];
    moneyAmountLabel.text = [NSString stringWithFormat:@"%d彩豆", noteAmount * [multipleTextField.text intValue] * 2];
    
    discountNo = [NSMutableString string];
    discountAmount = 0;
    [self.bgScrollView removeGestureRecognizer:sender];
    [self.bgScrollView setContentOffset:CGPointMake(0, 0) animated:YES];
}


-(BOOL)checkValue{
    if ([multipleTextField.text intValue]>999) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
                                                        message:@"倍数不能大于999"
                                                       delegate:nil
                                              cancelButtonTitle:@"确定"
                                              otherButtonTitles:nil,nil ];
        [alert show];
        multipleTextField.text =  @"999";
        return NO;
    }else if ((noteAmount * [multipleTextField.text intValue] * 2) > 2000000 ){
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
                                                        message:@"单个方案的总金额必须在2彩豆至2000000彩豆之间"
                                                       delegate:nil
                                              cancelButtonTitle:@"确定"
                                              otherButtonTitles:nil,nil ];
        [alert show];
        return NO;
    }
    return YES;
}

- (IBAction)clearListButtonClicked:(id)sender{
    if ([numberListTable numberOfRowsInSection:0]>0) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
                                                        message:@"确认清空列表？"
                                                       delegate:self 
                                              cancelButtonTitle:@"确定" 
                                              otherButtonTitles:@"取消",nil ];
        [alert show];
        
    }
}

- (void) alertView:(UIAlertView *)alertview clickedButtonAtIndex:(NSInteger)buttonIndex{
    if ([[alertview message] isEqualToString:@"确认购买？"]) {
        if (buttonIndex==0) {
            [self sureToBuy];
        }
    }else if ([[alertview message] isEqualToString:@"您还没有登录，请先登录"]) {
        if (buttonIndex == 0) {
            [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_LOGIN 
                                                                 fromController:self 
                                                                     withObject:nil 
                                                                    withObject2:nil];
        }
    } else {
    if (buttonIndex==0) {
        
        [numberArray removeAllObjects];
        [numberListTable reloadData];
        noteAmount = 0;
        for (JddShuangSeQiuNumber *ssqNumber in numberArray) {
            if ([ssqNumber.redBallArray count] != 6 ||
                [ssqNumber.blueBallArray count] != 1) {
                noteAmount += [JddCommonFunction countShuangSeQiuTotalNumber:[ssqNumber.redBallArray count] blueBallAmount:[ssqNumber.blueBallArray count]];
            }
            else {
                noteAmount++;
            }
        }
        multipleTextField.text = @"1";
        noteAmountLabel.text = [NSString stringWithFormat:@"%d注", noteAmount];
        multipleLabel.text = [NSString stringWithFormat:@"%@倍", multipleTextField.text];
        moneyAmountLabel.text = [NSString stringWithFormat:@"%d彩豆", noteAmount * [multipleTextField.text intValue] * 2];
        
        discountNo = [NSMutableString string];
        discountAmount = 0;
    }
    }
}


- (IBAction)plusButtonClicked:(id)sender{
    NSInteger multiple = [multipleTextField.text intValue];
    if (multiple>99998) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
                                                        message:@"倍数不能大于99999"
                                                       delegate:nil 
                                              cancelButtonTitle:@"确定" 
                                              otherButtonTitles:nil,nil ];
        [alert show];
        return;
    }
    multipleTextField.text = [NSString stringWithFormat:@"%d", ++multiple];
    multipleLabel.text = [NSString stringWithFormat:@"%@倍", multipleTextField.text];
    moneyAmountLabel.text = [NSString stringWithFormat:@"%d彩豆", noteAmount * [multipleTextField.text intValue] * 2];
}

- (IBAction)minusButtonClicked:(id)sender{
    NSInteger multiple = [multipleTextField.text intValue];
    if (multiple-- < 2) {
        multipleTextField.text = @"1";
        return;
    }
    
    multipleTextField.text = [NSString stringWithFormat:@"%d", multiple];
    multipleLabel.text = [NSString stringWithFormat:@"%@倍", multipleTextField.text];
    moneyAmountLabel.text = [NSString stringWithFormat:@"%d彩豆", noteAmount * [multipleTextField.text intValue] * 2];
}

- (NSMutableArray*)lotteryNumberList{
    NSMutableArray *paramNumberArray = [[NSMutableArray alloc] init];
    for (int i=0; i<[numberArray count]; ++i) {
        NSMutableString *lotteryNumberString = [NSMutableString string];
        JddShuangSeQiuNumber *ssqNumber = [numberArray objectAtIndex:i];
        NSMutableDictionary *numDic = [[NSMutableDictionary alloc] init];
        int playid = LOTTERY_PLAY_METHOD__DS_SHUANGSEQIU;
        if ([ssqNumber.redBallArray count] != 6 ||
                [ssqNumber.blueBallArray count] != 1) {
            playid = LOTTERY_PLAY_METHOD__FS_SHUANGSEQIU;
        }
        [numDic setObject:[NSNumber numberWithInt:playid] forKey:@"playid"];
        for (NSNumber *number in ssqNumber.redBallArray) {
            [lotteryNumberString appendFormat:@"%02d ", [number intValue]];
        };
        [lotteryNumberString appendString:@"+ "];
        for (NSNumber *number in ssqNumber.blueBallArray) {
            [lotteryNumberString appendFormat:@"%02d ", [number intValue]];
        }
        [numDic setObject:lotteryNumberString forKey:@"number"];
        [paramNumberArray addObject:numDic];
    }
    return paramNumberArray;
}

- (void)BuyLotteryOperationResult:(NSData *)result{
    [JddCommonFunction setWaitingViewHidden:YES fromController:self];
    if (result) {
        NSDictionary *ReDic = [NSJSONSerialization JSONObjectWithData:result options:NSJSONReadingMutableContainers error:nil];
        if([[ReDic objectForKey:@"Code"] intValue] == 0)
        {
            
            // modify by rainy  修改投注使用接口不经过web
             NSString * fanganhao = [ReDic objectForKey:@"Data"];
            JddLotteryIssue *ls = ((JddPickNumShuangSeQiuViewController *)self.fromController).currentLotteryIssue;
            alert1 = [JddAlertView getInstanceView];
            alert1.lssueString = fanganhao;
            alert1.moneylable = moneyAmountLabel.text;
            [alert1 alertBuyMessage:[NSString stringWithFormat:@"双色球%@期",ls.name]];
            
//            NSString *checkUrlString = [NSString stringWithFormat:@"%@?ck=%@",BASE_SERVER_IOS_BUY_LOTTERY_URL,[ReDic objectForKey:@"Data"]];
//            NSURL *checkUrl = [NSURL URLWithString:checkUrlString];
//            [[UIApplication sharedApplication] openURL:checkUrl];
        }else{
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"购彩失败"                                                  message:[ReDic objectForKey:@"Data"] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil,nil ];
            [alert show];
        }
//        [JddCommonFunction updateBuyLotteryListWithLotteryId:LOTTERY_TYPE_ID_SHUANGSEQIU];
    }
}

-(void)QueryDiscountOperationResult:(NSData *)result{
    if (result) {
        if ([JddDataParser parseDiscountResult:result discountNo:discountNo discountAmount:discountAmount]){
            
        }else {
            [JddCommonFunction messageBoxWithMessage:[JddError sharedInstance].message];
        }
    }
}

- (void)sureToBuy {
	if ([self checkValue]) {
		[JddCommonFunction setWaitingViewHidden:NO fromController:self];
		JddBuyLotteryOperation *operation2 = [[JddBuyLotteryOperation alloc] init];
		operation2.delegate = self;
		JddLotteryIssue *ls = ((JddPickNumShuangSeQiuViewController *)self.fromController).currentLotteryIssue;
        
		operation2.lotteryTypeId = [NSNumber numberWithInt:5];
		operation2.issueId = [NSNumber numberWithInt:[ls.code intValue]];
		operation2.multiple = [NSNumber numberWithInt:[multipleTextField.text intValue]];
		operation2.moneyAmount = [NSNumber numberWithFloat:noteAmount * [multipleTextField.text intValue] * 2];
		operation2.lotteryNumber = [self lotteryNumberList];
		[[JddGlobalParameter sharedInstance].operationQueue addOperation:operation2];
	}
}

- (IBAction)buyButtonClicked:(id)sender{
    int multiple = [multipleTextField.text intValue];
    if (![JddCommonFunction isLogin]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
                                                        message:@"您还没有登录，请先登录"
                                                       delegate:self
                                              cancelButtonTitle:@"确定"
                                              otherButtonTitles:@"取消",nil ];
        [alert show];
    } else {
        if (!agreeLotteryForFooterView.checkBoxBtn.selected) {
            [JddCommonFunction messageBoxWithMessage:BUY_NOT_READ];
        }
        else if ([numberArray count]==0) {
            [JddCommonFunction messageBoxWithMessage:BALL_COUNT_NULL];
        }else{
            if (multiple == 0) {
                [JddCommonFunction messageBoxWithMessage:MULTIPLE_Tip];
            }else{
                [self sureToBuy];
                /*
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"玩球球"
                                                                message:@"确认购买？"
                                                               delegate:self
                                                      cancelButtonTitle:@"确定"
                                                      otherButtonTitles:@"取消",nil ];
                [alert show];*/
            }
        }
    }
}

- (IBAction)continueSelectNumberButtonClicked:(id)sender{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)RandomSelectNumViewClickedButtonAtIndex:(NSNumber*)buttonIndex multiple:(NSNumber*)multiple{
    if ([buttonIndex intValue]== 1) {        
        for (int i = 0; i < [multiple intValue]; ++i) {
            JddShuangSeQiuNumber *number = [[JddShuangSeQiuNumber alloc] init];
            [JddCommonFunction generateBlueBallOfShuangSeQiuNumber:number count:1];
            [JddCommonFunction generateRedBallOfShuangSeQiuNumber:number count:6];
            
            [numberArray addObject:number];
        }
        
        [numberListTable reloadData];
        noteAmount = 0;
        for (JddShuangSeQiuNumber *ssqNumber in numberArray) {
            if ([ssqNumber.redBallArray count] != 6 ||
                [ssqNumber.blueBallArray count] != 1) {
                noteAmount += [JddCommonFunction countShuangSeQiuTotalNumber:[ssqNumber.redBallArray count] blueBallAmount:[ssqNumber.blueBallArray count]];
            }
            else {
                noteAmount++;
            }
        }
        noteAmountLabel.text = [NSString stringWithFormat:@"%d注", noteAmount];
        multipleLabel.text = [NSString stringWithFormat:@"%@倍", multipleTextField.text];
        moneyAmountLabel.text = [NSString stringWithFormat:@"%d彩豆", noteAmount * [multipleTextField.text intValue] * 2];
        
        discountNo = [NSMutableString string];
        discountAmount = 0;

    }    
}

- (IBAction)continueRandomSelectNumberButtonClicked:(id)sender{
//    CGRect rect = [[UIScreen mainScreen] bounds];
//    rect.origin.x = (rect.size.width - 251) / 2.0;
//    rect.origin.y = (rect.size.height - 139) / 2.0;
//    rect.size.width = 251.0;
//    rect.size.height = 139.0;
//
    randomSelectNumberDialog = [JddRandomSelectNumView getInstanceView];
//    [randomSelectNumberDialog setFrame:rect];
    randomSelectNumberDialog.type =1;
    randomSelectNumberDialog.delegate = self;
    [randomSelectNumberDialog okButtonClicked:nil];//yan
//    [randomSelectNumberDialog show];
    
}

-(IBAction)textFieldDidEndEditing:(id)sender{
    [multipleTextField resignFirstResponder];
}

- (void)numberFromArray:(NSArray*)inNumberArray{
    if (!numberArray) {
        numberArray = [NSMutableArray array];
    }
    [numberArray addObjectsFromArray:inNumberArray];
}

- (void)ShuangSeQiuListItemCellDeleteButtonClicked:(NSNumber *)rowNumber{
    for (int i = [rowNumber intValue] + 1; i < [numberArray count]; ++i) {
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
        UITableViewCell *cell = [numberListTable cellForRowAtIndexPath:indexPath];
        cell.tag--;
    }
    
    [numberArray removeObjectAtIndex:[rowNumber intValue]];    
    [numberListTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:[rowNumber intValue] inSection:0]] withRowAnimation:YES];
    noteAmount = 0;
    for (JddShuangSeQiuNumber *ssqNumber in numberArray) {
        if ([ssqNumber.redBallArray count] != 6 ||
            [ssqNumber.blueBallArray count] != 1) {
            noteAmount += [JddCommonFunction countShuangSeQiuTotalNumber:[ssqNumber.redBallArray count] blueBallAmount:[ssqNumber.blueBallArray count]];
        }
        else {
            noteAmount++;
        }
    }
    noteAmountLabel.text = [NSString stringWithFormat:@"%d注", noteAmount];
    multipleLabel.text = [NSString stringWithFormat:@"%@倍", multipleTextField.text];
    moneyAmountLabel.text = [NSString stringWithFormat:@"%d彩豆", noteAmount * [multipleTextField.text intValue] * 2];
    
    discountNo = [NSMutableString string];
    discountAmount = 0;

}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewCellEditingStyleDelete;
}

- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{
    return DELETE;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [numberArray count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 92.0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    JddShuangSeQiuListItemCell *cell = [JddShuangSeQiuListItemCell getInstanceView];
    
    JddShuangSeQiuNumber *ssqNumber = [numberArray objectAtIndex:indexPath.row];
    NSMutableString *redBallNumberString = [NSMutableString stringWithCapacity:[ssqNumber.redBallArray count]];
    for (NSNumber *number in [JddCommonFunction sortArray: ssqNumber.redBallArray]) {
        [redBallNumberString appendFormat:@"%02d ", [number intValue]];
    }
    cell.redBallLabel.text = redBallNumberString;
    
    NSMutableString *blueBallNumberString = [NSMutableString stringWithCapacity:[ssqNumber.blueBallArray count]];
    for (NSNumber *number in [JddCommonFunction sortArray: ssqNumber.blueBallArray]) {
        [blueBallNumberString appendFormat:@"%02d ", [number intValue]];
    }
    cell.blueBallLabel.text = blueBallNumberString;
    
    cell.tag = indexPath.row;
    cell.delegate = self;
    
    return cell;
}

/*
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section   // custom view for footer. will be adjusted to
{
    UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];
    footerView.backgroundColor = [UIColor redColor];
    //return footerView;
    return agreeLotteryForFooterView;
}*/



- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    agreeLotteryForFooterView = [JddAgreeLotteryForFooterView getInstanceView];
    agreeLotteryForFooterView.fromViewController = self;
    numberListTable.tableFooterView = agreeLotteryForFooterView;
//    [self.navigationItem setTitle:PAGE_SHUANGSEQIU_PICK_NUMBER_LIST];
    
        UILabel *customLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
        customLab.backgroundColor = [UIColor clearColor];
        [customLab setText:PAGE_SHUANGSEQIU_PICK_NUMBER_LIST];
        customLab.textAlignment = NSTextAlignmentCenter;

        [customLab setTextColor:[UIColor whiteColor]];
        customLab.font = [UIFont systemFontOfSize:19];
        self.navigationItem.titleView = customLab;    
}
- (void)viewWillDisappear:(BOOL)animated
{
    [MobClick endLogPageView:@"SSQ-list"];
    
    if ([multipleTextField.text length]==0) {
        multipleTextField.text = @"1";
    }
    [multipleTextField resignFirstResponder];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [MobClick beginLogPageView:@"SSQ-list"];

    
    [numberListTable reloadData];
    
    noteAmount = 0;
    for (JddShuangSeQiuNumber *ssqNumber in numberArray) {
        if ([ssqNumber.redBallArray count] != 6 ||
            [ssqNumber.blueBallArray count] != 1) {
            noteAmount += [JddCommonFunction countShuangSeQiuTotalNumber:[ssqNumber.redBallArray count] blueBallAmount:[ssqNumber.blueBallArray count]];
        }
        else {
            noteAmount++;
        }
    }
    noteAmountLabel.text = [NSString stringWithFormat:@"%d注", noteAmount];
    multipleLabel.text = [NSString stringWithFormat:@"%@倍", multipleTextField.text];
    moneyAmountLabel.text = [NSString stringWithFormat:@"%d彩豆", noteAmount * [multipleTextField.text intValue] * 2];
    
    discountNo = [NSMutableString string];
    discountAmount = 0;

}


- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
